package com.link2room.bumblebee.controller.manager;

import com.link2room.bumblebee.dto.param.base.DeleteWebSettingParamDto;
import com.link2room.bumblebee.dto.param.base.FindWebSettingParamDto;
import com.link2room.bumblebee.dto.param.base.WebSettingCreateParamDto;
import com.link2room.bumblebee.dto.param.base.WebSettingUpdateParamDto;
import com.link2room.bumblebee.facade.IWebSettingManagerFacadeService;
import com.link2room.common.dto.result.base.BaseResultDto;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/12/18
 */
@Api(tags = "获取站点信息")
@RestController
@RequestMapping("/manager/WebSettings")
public class WebSettingsController {
    @Resource
    private IWebSettingManagerFacadeService webSettingManagerFacadeService;

    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto listWebSettings(
            @RequestParam(name = "appid", required = false) String appid,
            @RequestParam(name = "componentAppid", required = false) String componentAppid,
            @RequestParam(name = "domain", required = false) String domain,
            @RequestParam(name = "name", required = false) String name,
            @RequestParam(name = "lhotelCode", required = false) String lhotelCode
    ) throws Exception {
        FindWebSettingParamDto paramDto = new FindWebSettingParamDto();
        paramDto.setAppid(appid);
        paramDto.setComponentAppid(componentAppid);
        paramDto.setDomain(domain);
        paramDto.setName(name);
        paramDto.setLhotelCode(lhotelCode);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(webSettingManagerFacadeService.listWebSettingsDto(paramDto));
        return l2rRs;
    }
    @RequestMapping(method = RequestMethod.POST)
    public BaseResultDto createWebSettings(

            @RequestBody WebSettingCreateParamDto paramDto
    ) throws Exception {
        webSettingManagerFacadeService.createWebSettings(paramDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }


    @RequestMapping(path = "/{code}", method = RequestMethod.GET)
    public BaseResultDto webSettings(@PathVariable("code") String code) throws Exception {
        FindWebSettingParamDto paramDto = new FindWebSettingParamDto();
        paramDto.setCode(code);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(webSettingManagerFacadeService.findWebSettingsDto(paramDto));
        return l2rRs;
    }

    @RequestMapping(path = "/{code}", method = RequestMethod.PUT)
    public BaseResultDto updateWebSettings(
            @PathVariable("code") String code,
            @RequestBody WebSettingUpdateParamDto paramDto
            ) throws Exception {
        paramDto.setCode(code);
        webSettingManagerFacadeService.updateCreateWebSettings(paramDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @RequestMapping(path = "/{code}", method = RequestMethod.DELETE)
    public BaseResultDto updateWebSettings(
            @PathVariable("code") String code
    ) throws Exception {
        DeleteWebSettingParamDto paramDto = new DeleteWebSettingParamDto();
        paramDto.setCode(code);
        webSettingManagerFacadeService.deleteWebSettings(paramDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }
}
